package priv.pront.code.lanqiao.competition.course.date0330;

import java.util.Scanner;

public class 最长子序列 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] c1 = scanner.nextLine().toCharArray();
        char[] c2 = scanner.nextLine().toCharArray();
        int j = 0;
        for (int i = 0; i < c1.length && j < c2.length; i++) {
            if (c1[i] == c2[j]) {
                j++;
            }
        }
        System.out.println(j);
    }
}
